﻿
using System.Collections.Generic;

namespace 城市天然气管道风险管理与决策系统
{
    internal class Util
    {
        public static string ParseScore(int a, int b)
        {
            return "(" + a.ToString() + "," + b.ToString() + "]";
        }

        public static double RankSum(int n, int i)
        {
            return (double)(2 * n + 1 - i) / (n * (n + 1));
        }

        public static double PR(int n, int i)
        {
            double tmp = 0.0;
            for (int j = 1; j <= n; j++) 
            {
                tmp += (double)(1.0 / j);
            }
            return (double)(1.0 / i) / tmp;
        }

        public static double RankOrderCentroid(int n, int i)
        {
            double tmp = 0.0;
            for (int j = 1; j <= n; j++) 
            {
                tmp += (double)(1.0 / i);
            }
            return (double)(1.0 / n) * tmp;
        }

        public static List<double> SortByOrder(List<int> order, List<double> to_be_sorted)
        {
            List<double> res = new List<double>();
            foreach (int i in order)
            {
                res.Add(to_be_sorted[i]);
            }
            return res;
        }

        public static double ComputeUtility(List<double> utis, List<double> weights)
        {
            int count = utis.Count;
            if (count != weights.Count) return -1;
            double res = 0.0;
            for(int i = 0; i < count; i++)
            {
                res += utis[i] * weights[i];
            }
            return res;
        }
    }
}
